import 'package:backend.core/core/domain/entities/api/web/api_web_one_time_purchased_item_transaction_offer_type.dart';
import 'package:equatable/equatable.dart';

const kApiWebOneTimePurchasedItemTransactionRegularOfferTypeValue = 'regular';

class ApiWebOneTimePurchasedItemTransactionOfferTypeDto extends Equatable {
  const ApiWebOneTimePurchasedItemTransactionOfferTypeDto._internal({
    required this.offerTypeString,
  });

  final String offerTypeString;

  @override
  List<Object?> get props {
    return [
      offerTypeString,
    ];
  }

  factory ApiWebOneTimePurchasedItemTransactionOfferTypeDto.fromString(String offerTypeString) {
    return ApiWebOneTimePurchasedItemTransactionOfferTypeDto._internal(
      offerTypeString: offerTypeString,
    );
  }

  factory ApiWebOneTimePurchasedItemTransactionOfferTypeDto.fromEntity(
      ApiWebOneTimePurchasedItemTransactionOfferType offerType) {
    late final String offerTypeString;

    if (offerType == ApiWebOneTimePurchasedItemTransactionOfferType.regular) {
      offerTypeString = kApiWebOneTimePurchasedItemTransactionRegularOfferTypeValue;
    }

    return ApiWebOneTimePurchasedItemTransactionOfferTypeDto._internal(
      offerTypeString: offerTypeString,
    );
  }

  @override
  String toString() {
    return offerTypeString;
  }

  ApiWebOneTimePurchasedItemTransactionOfferType toEntity() {
    if (offerTypeString == kApiWebOneTimePurchasedItemTransactionRegularOfferTypeValue) {
      return ApiWebOneTimePurchasedItemTransactionOfferType.regular;
    }

    throw UnimplementedError();
  }
}
